package com.admission.service;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.Transactional;
import org.springside.modules.orm.Page;
import org.springside.modules.orm.PropertyFilter;

import com.admission.dao.ArrayInfoDao;
import com.admission.dao.PayLogDao;
import com.admission.model.ArrayInfo;
import com.admission.model.PayLog;

@Repository
@Transactional
public class PayLogManager {

	private PayLogDao payLogDao;
	private ArrayInfoManager arrayInfoManager;
	private ArrayInfoDao arrayInfoDao;

	@Autowired
	public void setPayLogDao(PayLogDao payLogDao) {
		this.payLogDao = payLogDao;
	}
	
	public ArrayInfoManager getArrayInfoManager() {
		return arrayInfoManager;
	}

	@Autowired
	public void setArrayInfoManager(ArrayInfoManager arrayInfoManager) {
		this.arrayInfoManager = arrayInfoManager;
	}
	
	public List<PayLog> getAll() {
		return payLogDao.getAll();
	}
	
	public List<PayLog> getAllByStatus(String status){
      return  payLogDao.findBy("payStatus", status);
      }
	
	/**
	 * 通过id找唯一对象，无返回null
	 * @param id
	 * @return
	 */
	public PayLog getPayLogById(String id) {
  		return payLogDao.findUniqueBy("id", id);
  	}
	
	/**
	 * 通过身份证号找唯一对象，无返回null
	 * @param idnum
	 * @return
	 */
	public PayLog getPayLogByIdNum(String idnum) {
  		return payLogDao.findUniqueBy("idnum", idnum);
  	}
	
	/**
	 * 通过考生号找唯一对象，无返回null
	 * @param idnum
	 * @return
	 */
	public PayLog getPayLogByExamineeNo(String examineeNo) {
  		return payLogDao.findUniqueBy("examineeNo", examineeNo);
  	}
	
	/**
	 * 保存
	 * @param entity
	 * @throws Exception
	 */
	public void save(PayLog entity) throws Exception{
		payLogDao.save(entity);
	}
	
	/**
	 * 通过filter分页查询
	 * @param page
	 * @param filters
	 * @return
	 */
	public Page<PayLog> getPageByFilter(Page<PayLog> page,
			List<PropertyFilter> filters) {
		return payLogDao.findPage(page, filters);
	}
	
	
	/**
	 * 判断权限
	 * 
	 * @return
	 */
	public String checkConsult() {
		return arrayInfoManager.checkConsult(ArrayInfo.PAYLOG);
	}
	
	/**
	 * 改变状态
	 * 
	 * @param id
	 * @param status
	 */
	public void changeConsult(String status) {
		ArrayInfo a=arrayInfoDao.findUniqueBy("itemName",ArrayInfo.PAYLOG);
		a.setItemValue(status);
		arrayInfoDao.save(a);
	}
	
	/**
	 * 更新缴费状态
	 * @param idNnm
	 * @throws Exception
	 */
	public void UpdatePayStatus(String idNum, String payStatus, String payTime) throws Exception{
	   	PayLog payLog = payLogDao.findUniqueBy("idnum", idNum);
	   	payLog.setPayStatus(payStatus);
	   	payLog.setPayTime(payTime);
	   	payLogDao.save(payLog);
	}

	public ArrayInfoDao getArrayInfoDao() {
		return arrayInfoDao;
	}
	@Autowired
	public void setArrayInfoDao(ArrayInfoDao arrayInfoDao) {
		this.arrayInfoDao = arrayInfoDao;
	}
}
